<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<script src="./3.promise.js"></script>

<body>

</body>
<script>
    // 二、
    /* const promise1 = new Promise((resolve, reject) => {
        console.log('pp')
        setTimeout(() => {
            console.log('pppppp')
            resolve('success')
        }, 1000)
    })
    const promise2 = promise1.then(() => {
        throw new Error('error!!!')
    })

    console.log('promise11', promise1)
    console.log('promise22', promise2)

    setTimeout(() => {
        console.log('promise1', promise1)
        console.log('promise2', promise2)
    }, 2000) */
    //三、
    /* const promise = new Promise((resolve, reject) => {
        resolve('success1')
        reject('error')
        resolve('success2')
    })

    promise
        .then((res) => {
            console.log('then: ', res)
        })
        .catch((err) => {
            console.log('catch: ', err)
        }) */
    // 四、
    /* Promise.resolve(1)
        .then((res) => {
            console.log(res)
            return 2
        })
        .catch((err) => {
            return 3
        })
        .then((res) => {
            console.log(res)
        }) */
    // 五、
    /* const promise = new Promise((resolve, reject) => {
        setTimeout(() => {
            console.log('once')
            resolve('success')
        }, 1000)
    })

    const start = Date.now()
    promise.then((res) => {
        console.log(res, Date.now() - start)
    })
    promise.then((res) => {
        console.log(res, Date.now() - start)
    }) */
    // 六、
    /* Promise.resolve()
        .then(() => {
            return new Error('error!!!')
        })
        .then((res) => {
            console.log('then: ', res)
        })
        .catch((err) => {
            console.log('catch: ', err)
        }) */
    // 七、
    /*  const promise = Promise.resolve()
         .then(() => {
             return promise
         })
     promise.catch(console.error) */
    // 八、
    /* Promise.resolve(1)
        .then(2)
        .then(Promise.resolve(3))
        .then(console.log) */
    // 九、
    /* Promise.resolve()
        .then(function success(res) {
            throw new Error('error')
        }, function fail1(e) {
            console.error('fail1: ', e)
        })
        .catch(function fail2(e) {
            console.error('fail2: ', e)
        }) */
    // 十、
    /* process.nextTick(() => {
        console.log('nextTick')
    })
    Promise.resolve()
        .then(() => {
            console.log('then')
        })
    setImmediate(() => {
        console.log('setImmediate')
    })
    console.log('end') */
   /*  function callback(cb){
        cb();
        console.log('world');
    }
    callback(()=>{
        console.log('hellow ');
    }) */

</script>

</html>